package com.lkm.app_ui.m.Imple.fun;

import com.lkm.app.event.OnNetworkStateEvent;
import com.lkm.app_ui.AppConst;
import com.lkm.app_ui.RunTimeData;
import com.lkm.app_ui.log.SteelyardLogger;
import com.lkm.frame.otto.LinkBus;
import com.lkm.frame.otto.ObserverAutoNext;
import com.lkm.market2_0.m.steelyarddata.SteelyardDataModule;



public class HoldNewSteelyardInfo {

    
    private volatile boolean isLoadFormNet = false;

    
    private static HoldNewSteelyardInfo onceHoldNewSteelyardInfo = new HoldNewSteelyardInfo();

    private void holdInfo_() {
        if(isLoadFormNet){
            onceHoldNewSteelyardInfo = null;
            return;
        }
        LinkBus.registerReceiver(new ObserverAutoNext<OnNetworkStateEvent>() {
            @Override
            public void onReceiver(OnNetworkStateEvent data) {
                if(data.extIsNetworkOK){
                    SteelyardLogger.Info.onWaitNetLoad();

                    LinkBus.unregisterReceiver(this);
                    onceHoldNewSteelyardInfo = null;

                    if(isLoadFormNet)return;

                    SteelyardDataModule steelyardDataModule = AppConst.getModuleManager().loadModule(SteelyardDataModule.class);
                    if (steelyardDataModule != null)
                        steelyardDataModule.LoadSteelyardInfoForS(RunTimeData.LoaclSteelyardMac);
                }
            }

            @Override
            public Class getBusEventClass() {
                return OnNetworkStateEvent.class;
            }
        });
    }

    public static void holdInfo(){
        HoldNewSteelyardInfo holdNewSteelyardInfo = onceHoldNewSteelyardInfo;
        if(holdNewSteelyardInfo!=null){
            holdNewSteelyardInfo.holdInfo_();
        }
    }
    public static void isLoadFormNet(boolean isLoadFormNet){

        HoldNewSteelyardInfo holdNewSteelyardInfo = onceHoldNewSteelyardInfo;
        if(holdNewSteelyardInfo!=null){
            holdNewSteelyardInfo.isLoadFormNet = isLoadFormNet;
        }

        if(isLoadFormNet){
            onceHoldNewSteelyardInfo = null;
        }
    }
}
